/**
 * 
 */
package kr.co.insoft.core.model.paging;

import java.io.Serializable;
import java.util.HashMap;
import java.util.List;

import kr.co.insoft.framework.util.PagingUtil;
import flexjson.JSONSerializer;

/**
 * 검색은 차후 추가예정
 * 
 * @author IN-SOFT Inc. GoodwillDD(sylee@in-soft.co.kr)
 * 
 */
public class PagingModel implements Serializable {

	/**
	 * 
	 */
	private static final long serialVersionUID = 717355627410555104L;

	public String toString() {
		return (new JSONSerializer()).deepSerialize(this);
	}
	
	public PagingModel() {
		this.setCurrentPage(currentPage);
		this.setStartPageNum(currentPage);
		this.viewRow = 10;
		this.searchAndCondition = new HashMap<String, String>();
		this.searchOrCondition = new HashMap<String, String>();
	}

	/**
	 * @param lists
	 * @param totalCount
	 * @param pagingModel
	 */
	public PagingModel(List<?> lists, int totalCount,
			PagingModel pagingModel) {
		this.lists = lists;
		this.viewRow = pagingModel.getViewRow();
		this.paging = new PagingUtil(this.viewRow, this.blockSize, pagingModel.getCurrentPage(), totalCount);
		this.currentPage = pagingModel.getCurrentPage();
		this.setStartPageNum(pagingModel.getCurrentPage());
		this.searchAndCondition = pagingModel.getSearchAndCondition();
		this.searchOrCondition = pagingModel.getSearchOrCondition();
	}

	/**
	 * 하단에 보이는 페이징 블럭 사이즈 기본 10 고정
	 */
	int blockSize = 10;

	/**
	 * 화면에서 선택할 수 있는 목록 수
	 */
	int viewRow;
	/**
	 * 현재 페이지
	 */
	int currentPage = 1;
	
	int startPageNum;

	/**
	 * 보여줄 목록
	 */
	List<?> lists;

	/**
	 * 페이징 객체
	 */
	PagingUtil paging;

	HashMap<String, String> searchAndCondition;
	HashMap<String, String> searchOrCondition;

	/**
	 * @return the viewRow
	 */
	public int getViewRow() {
		return viewRow;
	}

	/**
	 * @param viewRow
	 *            the viewRow to set
	 */
	public void setViewRow(int viewRow) {
		this.viewRow = viewRow;
	}

	/**
	 * @return the currentPage
	 */
	public int getCurrentPage() {
		return currentPage;
	}

	/**
	 * @param currentPage
	 *            the currentPage to set
	 */
	public void setCurrentPage(int currentPage) {
		this.currentPage = currentPage;
		setStartPageNum(currentPage);
	}

	/**
	 * @return the lists
	 */
	public List<?> getLists() {
		return lists;
	}

	/**
	 * @param lists
	 *            the lists to set
	 */
	public void setLists(List<?> lists) {
		this.lists = lists;
	}

	/**
	 * @return the paging
	 */
	public PagingUtil getPaging() {
		return paging;
	}

	/**
	 * @param paging
	 *            the paging to set
	 */
	public void setPaging(PagingUtil paging) {
		this.paging = paging;
	}

	/**
	 * @return the blockSize
	 */
	public int getBlockSize() {
		return blockSize;
	}

	/**
	 * @param blockSize
	 *            the blockSize to set
	 */
	public void setBlockSize(int blockSize) {
		this.blockSize = blockSize;
	}

	/**
	 * @return the searchAndCondition
	 */
	public HashMap<String, String> getSearchAndCondition() {
		return searchAndCondition;
	}

	/**
	 * @param searchAndCondition
	 *            the searchAndCondition to set
	 */
	public void setSearchAndCondition(HashMap<String, String> searchAndCondition) {
		this.searchAndCondition = searchAndCondition;
	}

	/**
	 * @return the searchOrCondition
	 */
	public HashMap<String, String> getSearchOrCondition() {
		return searchOrCondition;
	}

	/**
	 * @param searchOrCondition
	 *            the searchOrCondition to set
	 */
	public void setSearchOrCondition(HashMap<String, String> searchOrCondition) {
		this.searchOrCondition = searchOrCondition;
	}

	/**
	 * @return the startPageNum
	 */
	public int getStartPageNum() {
		return startPageNum;
	}

	/**
	 * @param startPageNum the startPageNum to set
	 */
	public void setStartPageNum(int startPageNum) {
		this.startPageNum = (startPageNum - 1) * this.viewRow;;
	}

}
